package com.man.service.impl;


import com.man.mapper.UserMapper;
import com.man.pojo.Book;
import com.man.pojo.User;
import com.man.service.LoginService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


/**
 * @CallsName: loginServiceByImpl
 */
@Service
public class LoginServiceByImpl implements LoginService {

    @Autowired
    private UserMapper userMapper;

    /*增加*/
    @Override
    public void save(String username, String email, String password) {
        userMapper.insert(username, email, password);
    }

    /*删除*/
    @Override
    public void deleteByUserImpl(User username) {
        userMapper.deleteByUser(username);
    }

    /*修改*/
    @Override
    public void modify(User user) {
        user.setUpdateTime(LocalDateTime.now());//获取当前系统时间
        userMapper.update(user);
    }

    /*查询*/
    @Override
    public User getByUser(String username) {
        return userMapper.selectByUsername(username);
    }

    /*查询所有*/
    @Override
    public List<User> getAll() {
        return userMapper.selectAll();
    }

    /*查书*/
    @Override
    public Book getBook(String name) {
        return userMapper.selectByBook(name);
    }

    @Override
    public List<Book> getBookAll() {
        return userMapper.selectAllBook();
    }

    /*添加书籍*/
    @Override
    public void saveBook(String book, String bookName) {
        userMapper.addBook(book, bookName);
    }

    /*删除书*/
    @Override
    public void deleteBook(String book, Integer id) {
        userMapper.deleteByBook(book, id);
    }

    /*修改密码*/
    @Override
    public boolean updatePwd(String newPwd, Integer id) {
        userMapper.updatePwd(newPwd, id);
        return true;
    }

}
